package com.vito.dcs.modify.action;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.dubbo.config.annotation.Reference;
import com.vito.base.authoriza.action.BaseAction;
import com.vito.base.model.ResMsg;
import com.vito.base.model.Result;
import com.vito.dcs.modify.model.DataModifyModel;
import com.vito.dcs.modify.service.DataModifyService;

@Controller
@RequestMapping("/dcs/modify")
public class DataModifyAction extends BaseAction{

	@Reference
	private DataModifyService dataModifyService;
	
	private static final Logger log = LoggerFactory.getLogger(DataModifyAction.class);
	
	@RequestMapping("/saveDataModify")
	@ResponseBody
	public Result saveDataModify(DataModifyModel dataModifyModel){
		Result res = new Result();
		try {
			
			boolean queryIsLegal = dataModifyService.queryIsLegal(dataModifyModel);
			if(!queryIsLegal){
				res.setCode(Result.CODE_PARA_ERROR);
				res.setMsg("修正值不能大于计划值，请检查");
				return res;
			}
			dataModifyService.saveDataModify(dataModifyModel);
			res.setCode(Result.CODE_OK);
			res.setMsg(ResMsg.SAVESUC);
		} catch (Exception e) {
			log.error(ResMsg.SAVEERR, e);
			res.setCode(Result.CODE_ERROR);
			res.setMsg(ResMsg.SAVEERR);
		}
		return res;
	}
	@RequestMapping("/deleteDataModify")
	@ResponseBody
	public Result deleteDataModify(DataModifyModel dataModifyModel){
		Result res = new Result();
		try {
			dataModifyService.deleteDataModify(dataModifyModel);
			res.setCode(Result.CODE_OK);
			res.setMsg(ResMsg.DELSUC);
		} catch (Exception e) {
			log.error(ResMsg.DELERR, e);
			res.setCode(Result.CODE_ERROR);
			res.setMsg(ResMsg.DELERR);
		}
		return res;
	}
	@RequestMapping("/queryDataModifyBySectionId")
	@ResponseBody
	public Result queryDataModifyBySectionId(DataModifyModel dataModifyModel){
		Result res = new Result();
		try {
			DataModifyModel data = dataModifyService.queryDataModifyBySectionId(dataModifyModel);
			res.setCode(Result.CODE_OK);
			res.setData(data);
		} catch (Exception e) {
			log.error(ResMsg.EXECERR, e);
			res.setCode(Result.CODE_ERROR);
			res.setMsg(ResMsg.EXECERR);
		}
		return res;
	}
}
